//
// Templet.h
//
// $Id: //base/include/Templet.h
//
// Library: base
// Package: base
// Module : Templet
// Author :	Jelin,doitsjz@163.com
// Date	  :	10/30/2012
// 
// Definition of the Templet class.
//
// Copyright (c) 2012-2012, iGuard.
//
#include "BaseHTTPServerSession.h"
#include <sstream>

int BaseHTTPServerSession::handleMessage(BaseHTTPRequest& request)
{
	string method = request.getMethod();

	if (method == HTTPRequest::HTTP_GET)
		OnGetRequest(request);
	else if (method == HTTPRequest::HTTP_POST)
		OnPostRequest(request);
	else if (method == HTTPRequest::HTTP_PUT)
		OnPutRequest(request);
	else if (method == HTTPRequest::HTTP_DELETE)
		OnDeleteRequest(request);
	else
		;//default nothing ,future add err deal or selfdefine method
	return true;
}
int BaseHTTPServerSession::handleMessage(BaseHTTPResponse& reply)
{
	return 0;
}
int BaseHTTPServerSession::makeReply(int status,string &body,string& reply)
{
	BaseHTTPResponse rep((HTTPResponse::HTTPStatus)status);
//	rep.setUserAgent();
	if (!body.empty())
	{
		rep.setContentType("text/xml");
		rep.setContentBody(body);
		rep.setContentLength(body.length());
	}

	std::ostringstream ostr;
	rep.write(ostr);
	reply = ostr.str();

	return reply.length();
}